﻿using Castle.DynamicProxy;
using CNKI.TPI.Web.Base;
using CNKI.TPI.Web.Interface.Models;
using CNKI.TPI.Web.Search.IBLL;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;

namespace CNKI.TPI.Web.Interface.Areas.Resource.Controllers
{
    public class GetDocumentBySqlController : BaseApiController
    {
        private ISearchService searchService = null;
        public GetDocumentBySqlController(ISearchService searchService)
        {
            this.searchService = generator.CreateInterfaceProxyWithTarget<ISearchService>(searchService, new IInterceptor[] { new LogInterceptor() });
        }
        // GET api/getdocumentbysql/5
        public object Get(string sql, string pageIndex, string pageSize)
        {
            OutputEntityExt result = new OutputEntityExt();
            try
            {
                int count = 0;
                DataTable dt = searchService.GetDataBySql(sql, int.Parse(pageIndex), int.Parse(pageSize), out count);
                if (dt == null)
                {
                    result.Status = Status.Error;
                }
                else
                {
                    result.Status = Status.Success;
                    result.DataCount = count;
                    result.data = dt;
                }
            }
            catch (Exception ex)
            {
                LogOpr.Error(ex.ToString());
                result.Status = Status.Error;
                result.message = ex.Message;
            }
            return result;
        }
    }
}
